package com.mrjoew.weekend.web;

import com.mrjoew.weekend.entities.OptionException;
import com.mrjoew.weekend.entities.ValidException;
import com.mrjoew.weekend.entities.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Christopher Jones
 * @ClassName ExceptionController
 * @explain
 * @date 2020/6/18 0018 15:24
 */
@Slf4j
@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(ValidException.class)
    public Response<Object> handler(ValidException e) {
        log.error("ApiResException: ", e);
        return Response.error(Response.ERROR_VALIDATE, e.getMessage());
    }

    @ExceptionHandler(OptionException.class)
    public Response<Object> handler(OptionException e) {
        log.error("ApiResException: ", e);
        return Response.error(Response.ERROR_VALIDATE, e.getMessage());
    }
}
